package com.xc.controller.agent;

import com.xc.common.ServerResponse;
import com.xc.pojo.AgentUser;
import com.xc.service.IAgentUserService;
import com.xc.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author mipha
 * @version 1.0
 * @date 2019/2/24 3:44 PM
 */
@Controller
@RequestMapping("/agent/")
@Slf4j
public class AgentController {

    @Autowired
    IAgentUserService iAgentUserService;
    @Autowired
    IUserService iUserService;

    /**
     *  获取代理信息
     * @param request
     * @return
     */
    @RequestMapping("getAgentInfo.do")
    @ResponseBody
    public ServerResponse getAgentInfo(HttpServletRequest request){
        return iAgentUserService.getAgentInfo(request);
    }

    /**
     *  修改密码
     * @param oldPwd
     * @param newPwd
     * @param request
     * @return
     */
    @RequestMapping("updatePwd.do")
    @ResponseBody
    public ServerResponse updatePwd(@RequestParam("oldPwd") String oldPwd
            , @RequestParam("newPwd") String newPwd
            , HttpServletRequest request){
        return iAgentUserService.updatePwd(oldPwd,newPwd,request);
    }


    /**
     *  添加下级代理
     * @param request
     * @param agentName
     * @param agentPwd
     * @param agentPhone
     * @param agentRealName
     * @return
     */
    @RequestMapping("addAgent.do")
    @ResponseBody
    public ServerResponse addAgent(HttpServletRequest request,
                                   @RequestParam("agentName") String agentName,
                                   @RequestParam("agentPwd") String agentPwd,
                                   @RequestParam("agentPhone") String agentPhone,
                                   @RequestParam("agentRealName") String agentRealName){
        return iAgentUserService.addAgentUser(agentName,agentPwd,agentRealName,agentPhone,request);
    }


    /**
     *  获取当前代理的下级代理
     * @param request
     * @return
     */
    @RequestMapping("getSecondAgent.do")
    @ResponseBody
    public ServerResponse getSecondAgent(HttpServletRequest request){
        return iAgentUserService.getSecondAgent(request);
    }


    /**
     *  添加模拟用户
     * @param request
     * @param phone
     * @param pwd
     * @return
     */
    @RequestMapping("addSimulatedAccount.do")
    @ResponseBody
    public ServerResponse addSimulatedAccount(HttpServletRequest request,
                                   @RequestParam("phone") String phone,
                                   @RequestParam("amt") String amt,
                                   @RequestParam("pwd") String pwd){
        AgentUser agentUser = iAgentUserService.getCurrentAgent(request);
        return iUserService.addSimulatedAccount(agentUser.getId(),phone,pwd,amt,request);
    }






}
